//
//  HTTPHelper+Item.m
//  SalonManage
//
//  Created by wulongmin on 17/7/12.
//  Copyright © 2017年 lmtt. All rights reserved.
//

#import "HTTPHelper+Item.h"
#import "ItemInfo.h"

@implementation HTTPHelper (Item)


- (NSURLSessionDataTask *)getItemListWithItemType:(NSInteger)itemType
                                          success:(void(^)(NSArray <ItemInfo *> * itemList))success {
    
    
    NSString *url = [API_BASE_URL_STRING stringByAppendingString:@"item/list"];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"item_type"] = @(itemType);
    
    return [self get:url params:params useToken:YES showText:@"通信中" success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary * _Nullable result, HTTPStatus * _Nonnull status) {
        
        if ([status.code isEqualToString:KF_HTTP_OK]) {
            NSArray *itemInfoList = [ItemInfo mj_objectArrayWithKeyValuesArray:result];
            success(itemInfoList);
        }else {
            
            [MBProgressHUD showText:status.msg onView:nil];
            NSLog(@"%@",status);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}

@end
